package org.zzh.service.system.log;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zzh.dao.common.PageBean;
import org.zzh.dao.mapper.StLogMapper;
import org.zzh.domain.system.log.StLog;

import java.util.List;

@Service
public class StLogServiceImpl implements StLogService {
    @Autowired
    private StLogMapper stLogMapper;

    @Override
    public void save(StLog log) {
        stLogMapper.save(log);
    }

    @Override
    public PageBean<StLog> list(int page, int pageSize, String name) {
        PageHelper.startPage(page, pageSize);
        List<StLog> list = stLogMapper.list(name);
        PageInfo<StLog> stLogPageInfo = new PageInfo<>(list);
        PageBean<StLog> pageBean = new PageBean<>();
        pageBean.setData(stLogPageInfo.getList());
        pageBean.setTotalCount((int) stLogPageInfo.getTotal());
        pageBean.setTotalPage(stLogPageInfo.getPages());
        pageBean.setPage(page);
        pageBean.setPageSize(pageSize);
        return pageBean;
    }
}
